package com.hanrui.android.activity.message.supervise;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.hanrui.android.R;
import com.hanrui.android.adapter.SuperviseMonthListAdapter;
import com.hanrui.android.library.base.ActionBarBaseActivity;
import com.hanrui.android.model.SuperviseMonthListBean;
import com.hanrui.android.model.SuperviseWeekListBean;
import com.hanrui.android.net.contract.message.supervise.SuperviseContract;
import com.hanrui.android.net.presenter.message.supervise.SupervisePresenter;
import com.hanrui.android.widget.SearchEditText;

import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 月督办次级列表
 */
public class SuperviseMonthListActivity extends ActionBarBaseActivity<SupervisePresenter> implements SuperviseContract.View{

    @BindView(R.id.searchEditText)
    SearchEditText searchEditText;
    @BindView(R.id.recyclerview)
    RecyclerView mRecyclerView;
    String mid,title;
    @Inject
    SuperviseMonthListAdapter adapter;


    @Override
    protected void initInjector() {mActivityComponent.inject(this);}


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_supervise);

        unbinder = ButterKnife.bind(this);

        mid = getIntent().getStringExtra("mid");
        title = getIntent().getStringExtra("title");

        mTitleBar.setTitle(title);

        setIsPullRefresh(true);
        setRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                mPresenter.refresh(SuperviseMonthListActivity.this,mid,2);
            }
        });


        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.setAdapter(adapter);
        adapter.setEmptyView(getNoDataView(mRecyclerView));
        adapter.setEnableLoadMore(false);

        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

                SuperviseMonthListBean.MonthListBean bean = (SuperviseMonthListBean.MonthListBean) adapter.getItem(position);
                SuperviseMonthDetailActivity.start(SuperviseMonthListActivity.this,bean.getId(),"2");

            }
        });

    }


    @Override
    protected void onResume() {
        super.onResume();
        setRefreshing();
        mPresenter.refresh(this,mid,2);
    }

    public static void start(Context context, String mid, String title){
        Intent intent = new Intent(context,SuperviseMonthListActivity.class);
        intent.putExtra("mid",mid);
        intent.putExtra("title",title);
        context.startActivity(intent);
    }

    @Override
    public void overSeeWeekList(List<SuperviseWeekListBean.WeekListBean> dataList, int loadType) {

    }

    @Override
    public void overSeeMonthList(List<SuperviseMonthListBean.MonthListBean> dataList, int loadType) {

        setLoadDataResult(adapter,dataList,loadType,false);

    }
}
